# To change this template, choose Tools | Templates
# and open the template in the editor.

from direct.gui.OnscreenText import OnscreenText
from direct.gui.DirectGui import *
from panda3d.core import *
import sys

class GUI():
    def __init__(self):
        nothing = "cool"

    def MainMenuGui(self):
        self.MainFrame = DirectFrame(frameColor=(0, 0, 0, 1),frameSize=(-1, 3, -1, 1),pos=(1, 0, -1))
        self.MainFrame.reparentTo(base.a2dTopLeft)
        self.play= DirectButton(text = ("Play", "Play", "Play", "disabled"),frameSize=(-1, 3.5, -0.5, 1),text_pos = (1,0),command = self.Play,extraArgs = ["PLAY"])
        self.options= DirectButton(text = ("Options", "Options", "Options", "disabled"),frameSize=(-1, 3.5, -0.5, 1),text_pos = (1,0),command = self.button,extraArgs = ["OPTIONS"])
        self.exit= DirectButton(text = ("Quit", "Quit", "Quit", "disabled"),frameSize=(-1, 3.5, -0.5, 1),text_pos = (1,0),command = self.button,extraArgs = ["EXIT"])
        #Play Button
        self.play.setScale(0.1)
        self.play.setPos(-0.7,0,0.7)
        self.play.reparentTo(self.MainFrame)
        #Options Button
        self.options.setScale(0.1)
        self.options.setPos(-0.7,0,0.55)
        self.options.reparentTo(self.MainFrame)
        #Exit Button
        self.exit.setScale(0.1)
        self.exit.setPos(-0.7,0,0.4)
        self.exit.reparentTo(self.MainFrame)
        
    def OptionsMenuGui(self):
        self.OptionsFrame = DirectFrame(frameColor=(0, 0, 0, 1),frameSize=(-1, 3, -1, 1),pos=(1, 0, -1))
        self.OptionsFrame.reparentTo(base.a2dTopLeft)
        self.sound= DirectButton(text = ("Sound", "Sound", "Sound", "disabled"),frameSize=(-1, 5, -0.5, 1),text_pos = (1,0),command = self.button,extraArgs = ["SOUND"])
        self.controls= DirectButton(text = ("Controls", "Controls", "Controls", "disabled"),frameSize=(-1, 5, -0.5, 1),text_pos = (1,0),command = self.button,extraArgs = ["CONTROL"])
        self.video= DirectButton(text = ("Video", "Video", "Video", "disabled"),frameSize=(-1, 5, -0.5, 1),text_pos = (1,0),command = self.button,extraArgs = ["VIDEO"])
        self.multi= DirectButton(text = ("Multiplayer", "Multiplayer", "Multiplayer", "disabled"),frameSize=(-1, 5, -0.5, 1),text_pos = (1.9,0),command = self.button,extraArgs = ["MULTI"])
        self.back= DirectButton(text = ("Back", "Back", "Back", "disabled"),frameSize=(-1, 5, -0.5, 1),text_pos = (1,0),command = self.button,extraArgs = ["BACK"])
        #Play Button
        self.sound.setScale(0.1)
        self.sound.setPos(-0.8,0,0.7)
        self.sound.reparentTo(self.OptionsFrame)
        #Options Button
        self.controls.setScale(0.1)
        self.controls.setPos(-0.25,0,0.7)
        self.controls.reparentTo(self.OptionsFrame)
        #Exit Button
        self.video.setScale(0.1)
        self.video.setPos(0.35,0,0.7)
        self.video.reparentTo(self.OptionsFrame)
        #MULTI Buttong
        self.multi.setScale(0.1)
        self.multi.setPos(0.85,0,0.7)
        #back
        self.multi.reparentTo(self.OptionsFrame)
        self.back.setScale(0.1)
        self.back.setPos(0.35,0,-0.9)
        self.back.reparentTo(self.OptionsFrame)
        self.optionlist = [self.sound,self.controls,self.video,self.multi]
        self.OptionFrames()
        self.button("SOUND")
    def OptionFrames(self):
        self.VideoFrame = DirectFrame(frameColor=(0, 0, 0, 1),frameSize=(-1, 3, -0.5, 0.5),pos=(0, 0, 0))
        self.VideoFrame.reparentTo(self.OptionsFrame)
        numItemsVisible = 4
        itemHeight = 0.11

        resolution = DirectScrolledList(
            decButton_pos= (0.35, 0, 0.53),
            decButton_text = "Dec",
            decButton_text_scale = 0.04,
            decButton_borderWidth = (0.005, 0.005),

            incButton_pos= (0.35, 0, -0.02),
            incButton_text = "Inc",
            incButton_text_scale = 0.04,
            incButton_borderWidth = (0.005, 0.005),

            frameSize = (0.0, 0.8, -0.10, 0.60),
            frameColor = (0.8,0.8,0.8,0.5),
            pos = (-1, 0, 0),
            numItemsVisible = 4,
            forceHeight = 0.1,
            itemFrame_frameSize = (-0.2, 0.2, -0.37, 0.11),
            itemFrame_pos = (0.35, 0, 0.4),
            )
        resolution.setPos(-0.5,0,-0.5)
        resolution.reparentTo(self.VideoFrame)
        mybar = DirectScrollBar(range=(0, 100), value=50, pageSize=3, orientation= DGG.VERTICAL)
        mybar.setPos(0,0,0)
        for fruit in base.res:
            l = DirectLabel(text = fruit, text_scale=0.1)
            resolution.addItem(l)
        mybar.reparentTo(resolution)
        shadows = DirectCheckButton(text="PCF Shadows" ,scale=0.1)
        shadows.reparentTo(self.VideoFrame)
        shadows.setPos(0,0,0.5)
        self.VideoFrame.hide()
    def TeamButtons(self):
            CTmaps = loader.loadModel('textures/cards/ct/ct_buttonmap.egg')
            Tmaps = loader.loadModel('textures/cards/t/t_buttonmap.egg')
            self.teamCT= DirectButton(geom = (CTmaps.find('**/button_ready'),CTmaps.find('**/button_rollover')),frameSize=(-0.5, 1, -1, 1),command = self.button,extraArgs = ["CT"])
            self.teamT= DirectButton(geom = (Tmaps.find('**/button_ready'),Tmaps.find('**/button_rollover')),frameSize=(-1, 0.5, -1, 1),command = self.button,extraArgs = ["T"])
            self.teamCT.reparentTo(base.a2dTopCenter)
            self.teamCT.setPos(0.5,0,-1)
            self.teamT.reparentTo(base.a2dTopCenter)
            self.teamT.setPos(-0.5,0,-1)
    def button(self,id,extra="zilch"):
        if extra == "PLAY":
            if id != "":
                base.settings[0] = id
                self.b.destroy()
                self.TeamButtons()
        elif id == "CT":
            self.teamCT.destroy()
            self.teamT.destroy()
            id = 0
            base.LoadGame("assault",id)
        elif id == "T":
            self.teamCT.destroy()
            self.teamT.destroy()
            id = 1
            base.LoadGame("assault",id)
        elif id == "OPTIONS":
            self.MainFrame.hide()
            self.OptionsMenuGui()
        elif id == "EXIT":
            base.props.setCursorHidden(False)
            base.win.requestProperties(base.props)
            base.pause = True
            self.dialog = YesNoDialog(dialogName="Do You Want To Exit?", text="Are You Sure? \nDont change resolution here", command=self.Exit)
        elif id == "SOUND":
            for i in self.optionlist:
                if i != self.sound:
                    i["relief"] = 2
                    i["frameColor"] = (0.2,0.2,0.2,1)
                else:
                    i["relief"] = 1
                    i["frameColor"] = (1,1,1,1)
        elif id == "CONTROL":
            for i in self.optionlist:
                if i != self.controls:
                    i["relief"] = 2
                    i["frameColor"] = (0.2,0.2,0.2,1)
                else:
                    i["relief"] = 1
                    i["frameColor"] = (1,1,1,1)
        elif id == "VIDEO":
            self.VideoFrame.show()
            for i in self.optionlist:
                if i != self.video:
                    i["relief"] = 2
                    i["frameColor"] = (0.2,0.2,0.2,1)
                else:
                    i["relief"] = 1
                    i["frameColor"] = (1,1,1,1)
        elif id == "MULTI":
            for i in self.optionlist:
                if i != self.multi:
                    i["relief"] = 2
                    i["frameColor"] = (0.2,0.2,0.2,1)
                else:
                    i["relief"] = 1
                    i["frameColor"] = (1,1,1,1)
        elif id == "BACK":
            self.OptionsFrame.hide()
            self.MainFrame.show()

    def Exit(self,arg):
	if(arg):
            base.userExit()
        else:
            if self.MainFrame.isHidden():
                self.dialog.hide()
                base.pause = False
                base.props.setCursorHidden(True)
                base.win.requestProperties(base.props)
            else:
                self.dialog.hide()

    def Play(self,arg):
        print arg
        self.MainFrame.hide()
        self.b = DirectEntry(text = "" ,scale=.1,initialText=base.settings[0], numLines = 1,focus=1,command=self.button,extraArgs = ["PLAY"])
        self.b.setPos(-0.5,0,0)
    def clearText(node):
	node.enterText('')
    def PlayingGui(self):
         #hp
        self.GuiHP=OnscreenImage(image = 'textures/Gui/Hp.png', pos = (-1.2, 0, -0.9))
        self.GuiHP.setScale(0.14)
        self.GuiHP.setTransparency(TransparencyAttrib.MAlpha)
        #hp words
        self.GuiHPWord = OnscreenText(text = "100", pos = (-1.0, -0.95), scale = 0.14,mayChange =1,fg = (1,1,1,1))
        self.GuiTimeWord = OnscreenText(text = "0", pos = (0.4, -0.95), scale = 0.14,mayChange =1,fg = (1,1,1,1))
        #armour
        self.GuiArmour=OnscreenImage(image = 'textures/Gui/Armour.png', pos = (-0.7, 0, -0.9))
        self.GuiArmour.setScale(0.08)
        self.GuiArmour.setTransparency(TransparencyAttrib.MAlpha)
        #crosshair
        self.GuiCross=OnscreenImage(image = 'textures/Gui/Crosshair.png', pos = (0.0, 0, 0.0))
        self.GuiCross.setScale(0.05)
        self.GuiCross.setTransparency(TransparencyAttrib.MAlpha)